﻿using _10_01Prism框架.Views;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _10_01Prism框架.ViewModels
{
    public class MainViewModel : BindableBase
    {


		#region 方法1
		//public DelegateCommand<string> OpenCommand { get; private set; }
		//public MainViewModel()
		//{
		//    OpenCommand = new DelegateCommand<string>(Open);
		//}
		//private object body;
		//public object Body
		//{
		//    get { return body; }
		//    set { body = value; RaisePropertyChanged(); }
		//}
		//private void Open(string obj)
		//{
		//    switch (obj)
		//    {
		//        case "ViewA": Body = new ViewA(); break;
		//        case "ViewB": Body = new ViewB(); break;
		//        case "ViewC": Body = new ViewC(); break;
		//    }
		//} 
		#endregion

		#region 方法2 使用prism中的区域方法
		public readonly IRegionManager regionManager;
		public DelegateCommand<string> OpenCommand { get;private set;}

		public MainViewModel(IRegionManager regionManager) 
		{
			OpenCommand = new DelegateCommand<string>(Open);
			this.regionManager=regionManager;
		}

		private void Open(string obj)
		{
			//通过IRegionManager接口获取当前全局定义可用区域
			//往这个区域动态的去设置内容
			//设置内容的方式是通过依赖注入的形式
			regionManager.Regions["ContentRegion"].RequestNavigate(obj);
		}

		#endregion
	}
}
